package com.sh.weblogspringboot.admin.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @author songHai
 * @Classname Knife4jAdminConfig
 * @Description
 * @Date 2025/3/23 22:03
 */
@Configuration
@EnableSwagger2WebMvc
@Profile("dev")
public class Knife4jAdminConfig {

    @Bean("adminApi")
    public Docket createApiDoc() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(buildApiInfo())
                .groupName("Admin 后台接口")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sh.weblogspringboot.admin.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

    /**
     * 构建API信息.
     *
     * @return
     */
    private ApiInfo buildApiInfo() {
        return new ApiInfoBuilder()
                .title("Weblog 博客Admin 后台接口文档")
                .description("Weblog是一款由Springboot + Vue3.2 + Vite4.3开发前后端分离的博客。")
                .termsOfServiceUrl("https://www.xxx.weblog.com/")
                .contact(new Contact("songhai", "https://www.sh.weblog.com", "xxxxx@qq.com"))
                .version("1.0")
                .build();
    }
}
